<?php
require_once './header.php';
require_once './core/sql.php';
$sql = new SqlS();
?>
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="initial-scale=1.0,width=device-width,user-scalable=0,maximum-scale=1.0"/>
        <title>自定义内容（预览）</title>
        <link rel="stylesheet" href="./css/base.css">
        <link rel="stylesheet" href="./css/index.css">
        <link rel="stylesheet" href="./Mdate/needcss/Mdate.css">
        <script>
            function adapte() {//适配
                var designWidth = 1080, rem2px = 100;
                document.documentElement.style.fontSize = window.innerWidth / designWidth * rem2px + "px";
            }
            adapte();
        </script>
    </head>
    <style type="text/css">
        .demo {
            display: flex;
            display: -webkit-flex;
            display: -moz-flex;
        }

        .demo > input {
            flex: 1;
            -webkit-flex: 1;
            -moz-flex: 1;
        }

        .demo > button {
            background-color: #c22020;
            color: #fff;
            width: 20%;
            border-radius: 3px;
            margin-right: 20px;
            font-size: 10px;
        }
    </style>
    <body>
    <div class="bulid-form fs36">
        <ul class="lists flex">
            <?php
            // 默认问题
            if (isset($_SESSION['listArray'])) {
                $de_array = $_SESSION['listArray'][0];
                $de_length = count($de_array);
                for ($i = 0; $i < $de_length; $i++) {
                    $result = $sql->buildDeQuestion($de_array[$i]);
                    list($qid, $type, $modes, $bgText) = $result;
                    switch ($type) {
                        case '1':
                            // 单选
                            $modes_array = json_decode($modes);
                            $modes_count = count($modes_array);
                            ?>
                            <li>
                                <span><?= $de_array[$i] ?></span>
                                <div class="radio">
                                    <?php
                                    for ($m = 0; $m < $modes_count; $m++) {
                                        if ($modes_array[$m] != '') {
                                            if ($m == 0) {
                                                ?>
                                                <span class="active">
                                        <?= $modes_array[$m] ?>
                                        </span>
                                                <?php
                                            } else {
                                                ?>
                                                <span>
                                        <?= $modes_array[$m] ?>
                                        </span>
                                                <?php
                                            }
                                        }
                                    }
                                    ?>
                                </div>
                            </li>
                            <?php
                            break;
                        case '2':
                            // 多选
                            $content_array = $sql->searchQuContent($_SESSION['f-uid'], $qid);
                            $content_count = count($content_array);
                            ?>
                            <li class="checkbox">
                                <span><?= $de_array[$i] ?>选择</span><span>(可多选)</span>
                                <ul class="flex fs36">
                                    <?php
                                    for ($n = 0; $n < $content_count; $n++) {
                                        if ($content_array[$n] != '') {
                                            if ($n == 0) {
                                                ?>
                                                <li class="active"><?= $content_array[$n] ?></li>
                                                <?php
                                            } else {
                                                ?>
                                                <li><?= $content_array[$n] ?></li>
                                                <?php
                                            }
                                        }
                                    }
                                    ?>
                                </ul>
                            </li>
                            <?php
                            break;
                        case '3':
                            // 单行文本
                            $modes_array = json_decode($modes);
                            ?>
                            <li>
                                <span><?= $de_array[$i] ?></span>
                                <input type="text" maxlength="<?= $modes_array[0] ?>" placeholder="<?= $bgText ?>">
                            </li>
                            <?php
                            break;
                        case '5':
                            // 日期
                            $modes_array = json_decode($modes);
                            ?>
                            <li>
                                <div class="demo">
                                    <span class="qu-name"><?= $de_array[$i] ?></span>
                                    <input type="text" id="dateSelectorDate" placeholder="<?= $bgText ?>"
                                           maxlength="<?= $modes_array[0] ?>">
                                    <button type="button" id="dateShowBtn">选择日期</button>
                                </div>
                            </li>
                            <?php
                            break;
                        case '6':
                            // 单行数字
                            $modes_array = json_decode($modes);
                            ?>
                            <li>
                                <span><?= $de_array[$i] ?></span>
                                <input type="text" onkeyup="value=value.replace(/[^\d]/g,'')" type="text"
                                       maxlength="<?= $modes_array[0] ?>" value="" placeholder="<?= $bgText ?>">
                            </li>
                            <?php
                            break;
                        case '7':
                            //手机
                            $modes_array = json_decode($modes);
                            ?>
                            <li>
                                <span><?= $de_array[$i] ?></span>
                                <input type="text" onkeyup="value=value.replace(/[^\d]/g,'')" type="text"
                                       maxlength="<?= $modes_array[0] ?>" value="" placeholder="<?= $bgText ?>">
                            </li>
                            <?php
                            break;
                        default :
                    }
                }
            }
            //自定义问题：
            if (isset($_SESSION['f-uid']) && isset($_SESSION['listArray'])) {
                $de_array = $_SESSION['listArray'][1];
                $de_length = count($de_array);
                for ($i = 0; $i < $de_length; $i++) {
                    list($type, $modes, $show) = $sql->searchDiShowQuContent($de_array[$i], $_SESSION['f-uid']);
                    switch ($show) {
                        case '0':
                            switch ($type) {
                                case '1':
                                    // 单选
                                    $modes_array = json_decode($modes);
                                    $modes_count = count($modes_array);
                                    ?>
                                    <li>
                                        <span><?= $de_array[$i] ?></span>
                                        <div class="radio">
                                            <?php
                                            for ($m = 0; $m < $modes_count; $m++) {
                                                if ($modes_array[$m] != '') {
                                                    if ($m == 0) {
                                                        ?>
                                                        <span class="active">
                                        <?= $modes_array[$m] ?>
                                        </span>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <span>
                                        <?= $modes_array[$m] ?>
                                        </span>
                                                        <?php
                                                    }
                                                }
                                            }
                                            ?>
                                        </div>
                                    </li>
                                    <?php
                                    break;
                                case '2':
                                    // 多选
                                    $content_array = json_decode($modes);
                                    $content_count = count($content_array);
                                    ?>
                                    <li class="checkbox">
                                        <span><?= $de_array[$i] ?>选择</span><span>(可多选)</span>
                                        <ul class="flex fs36">
                                            <?php
                                            for ($n = 0; $n < $content_count; $n++) {
                                                if ($content_array[$n] != '') {
                                                    if ($n == 0) {
                                                        ?>
                                                        <li class="active"><?= $content_array[$n] ?></li>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <li><?= $content_array[$n] ?></li>
                                                        <?php
                                                    }
                                                }
                                            }
                                            ?>
                                        </ul>
                                    </li>
                                    <?php
                                    break;
                                default :
                            }
                            break;
                        case '1':
                            // 单行文本
                            ?>
                            <li>
                                <span><?= $de_array[$i] ?></span>
                                <input type="text" maxlength="100" placeholder="请填写<?= $de_array[$i] ?>">
                            </li>
                            <?php
                            break;
                            break;
                        default:
                    }
                }
            }
            ?>
            <li style="text-align: center; color: #a0a0a0;">已经到底了</li>
        </ul>
        <div class="btn">
            <button>
                <a href="./makeForm.php">< 返回修改</a>
            </button><button onclick="ajax_saveForm()">
                <a class="wait" href="javascript:;">保存并继续制作海报 ></a>
            </button>
        </div>
    </div>
    <script src='./script/jquery.js'></script>
    <script src='./script/index.js'></script>
    <script></script>
    </body>
    </html>
<?php
require_once './footer.php';